/*
 * PropertiesDialog.cs - Wordtrainer
 * 
 * Copyright (C) 1998-2007 Markus Kilås
 *               
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 2 of the License, or
 * (at your option) any later version.
 * 
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 * 
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA
 *
 * Authors:
 *   Markus Kilås <markus@markuspage.com>
 * 
 */

using System;

namespace WtSharp
{
	
	
	public partial class PropertiesDialog : Gtk.Dialog
	{	
		private WtDocument m_document;
		
		public PropertiesDialog(Gtk.Window parent, WtDocument document) : base("Properties "+document.FileTitle, parent, Gtk.DialogFlags.Modal)
		{
			this.Build();
			m_document = document;
			labelFileTitle.Text = document.FileTitle;
			string fileType = (string)document.Info["VERSION"];
			if(fileType == null)
			{
				labelFileType.Text = "";
				labelCreator.Text = "";
				labelFileName.Text = "(Not saved yet)";
				labelSize.Text = "0 bytes";
			}
			else
			{
				if(fileType.Equals("1.0"))
					labelFileType.Text = "Wordtrainer 1.x";
				else if(fileType.Equals("2.0"))
					labelFileType.Text = "Wordtrainer 2.x-3.0";
				else
					labelFileType.Text = "Unknown or later version";
				labelCreator.Text = (string)document.Info["CREATOR"];
				labelFileName.Text = document.FileName;
				System.IO.FileInfo fileInfo = new System.IO.FileInfo(document.FileName);
				labelSize.Text = ""+fileInfo.Length+" bytes";
			}
			labelNumWords.Text = ""+document.Words.Count;
			
			entryTitle.Text = (string)document.Info["TITLE"];
			entryOwner.Text = (string)document.Info["OWNER"];
			textviewDescription.Buffer.Text = (string)document.Info["DESCRIPTION"];
		}

		protected virtual void OnButtonOkClicked (object sender, System.EventArgs e)
		{
			m_document.Info["TITLE"] = entryTitle.Text;
			m_document.Info["OWNER"] = entryOwner.Text;
			m_document.Info["DESCRIPTION"] = textviewDescription.Buffer.Text;
			Destroy();
		}

		protected virtual void OnButtonCancelClicked (object sender, System.EventArgs e)
		{
			Destroy();
		}
		
	}
}
